import { defineStore } from "pinia";
import { ref } from "vue";

export const useUserInfoStore = defineStore('userInfo',
    () => {
        const userInfo = ref({})
        const currentRole = ref(0)

        const setUserInfo = (newUserInfo) => {
            userInfo.value = newUserInfo
            currentRole.value = newUserInfo.role

            // 添加调试信息
            console.log('用户信息已存储:', newUserInfo);
        }

        const switchRole = (role) => {
            console.log('切换角色:', role);
            currentRole.value = role
        }

        // 清理值
        const removeUserInfo = () => {
            userInfo.value = {}
        }

        return {
            userInfo,
            currentRole,
            setUserInfo,
            removeUserInfo,
            switchRole
        }
    },
    {
        persist: true
    });